package pl.smath.expression.model.presentation;

import pl.smath.expression.model.NumberTerm;
import pl.smath.expression.model.Term;
import pl.smath.expression.model.VariableTerm;

public class FactorialTerm extends PresentationTerm {

	private Term innerTerm;
	
	public FactorialTerm(Term innerTerm) {
		super("!");
		this.innerTerm = innerTerm;
	}
	
	public Term getInnerTerm() {
		return innerTerm;
	}

	/**
	 * Sprawdzenie czy 2 wartości bezwgledne wyrazenia sa sobie równowazne.
	 */
	public boolean isAbsTheSame(Term term){
		if (!(term instanceof FactorialTerm))
			return false;
		
		return innerTerm.isAbsTheSame(((FactorialTerm)term).getInnerTerm());
	}
	
	public String toString(){

		String output = "";
		
		if(isNegative())
			output = "-";
		
		if( !(innerTerm instanceof NumberTerm || innerTerm instanceof VariableTerm) || innerTerm.isNegative()){
			output += "(" + innerTerm.toString() + ")";
		}
		else{
			output += innerTerm.toString();
		}
		
		output += "!";
		
		return output;
	}

}
